const md5 = require('md5')
const axios = require('axios')
const { dateFormat } = require('./date')
const HOST = 'http://app.xgjc.hanyunmmip.cn/VehExternal/vehicleData'

const INDEX = '742fcf62-8af7-4c7c-b475-f97d932765c0'
const CHECKSTRING = 'QzVQeJCd'

const getAccessToken = () => {
  const date = dateFormat(new Date(), 'Y-m-d').replace(/-/g, '')
  const token = md5(`${CHECKSTRING}${date}`)
  return token
}

// 请求数据
async function getData () {
//   const { HOST } = CONFIG
  const token = getAccessToken()
  const url = `${HOST}?index=${INDEX}&token=${token}`
  const res = await axios.post(url)
  return res.data
};

module.exports = getData
